<%@page import="model.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	User u = new User();
	if (!u.isAdmin((String) session.getAttribute("lv"))) {
		response.sendRedirect("../index.jsp");
	}
	Message message = new Message();
	String orby = (String) request.getParameter("sort");
	if (orby != null) {
		if (orby.equals("n"))
			orby = "m_name";
		if (orby.equals("t"))
			orby = "m_title";
		if (orby.equals("c"))
			orby = "m_content";
		if (orby.equals("by"))
			orby = "uid";
	}
	int[] mid = message.getMID(orby);
%>
<title>MYFILM - Manage Message</title>
<div>
	<h2>Manage Categories</h2>
</div>
<table>
	<thead>
		<tr>
			<th><a href="view-message.jsp?sort=n">Message</a></th>
			<th><a href="view-message.jsp?sort=t">Title</a></th>
			<th><a href="view-message.jsp?sort=c">Info</a></th>
			<th><a href="view-message.jsp?sort=by">Posted by</a></th>
			<th>Edit</th>
			<th>Delete</th>
		</tr>
	</thead>
	<tbody>
	<tr><td><a href="messages.jsp?site=a">Add</a></td><td></td><td></td><td></td><td></td><td></td></tr>
		<%
			for (int i = 0; i < mid.length; i++) {
				message = message.getMg(mid[i]);
		%>
		<tr>
			<td><%=message.getM_name()%></td>
			<td><%=message.getM_title()%></td>
			<td><%=message.getM_content()%></td>
			<td><%=u.getFullName(u.getUserByID(message.getUid())
						.getUserName(), 1)%></td>
			<td><a class='edit' href='messages.jsp?site=e&mid=<%=mid[i]%>'>Edit</a></td>
			<td><a class='delete' href='delete.jsp?mid=<%=mid[i]%>'>Delete</a></td>
		</tr>
		<%
			}
		%>
		
	</tbody>
</table>